import sqlite3
import random
from datetime import datetime, timedelta
from faker import Faker
import time
from typing import Generator

# 初始化Faker库生成虚假数据
fake = Faker('zh_CN')

#数据生成开始日期
start_date = "2025-01-01"

#数据生成结束日期
end_date = "2025-08-20"

#每日生成条数
daily_gene_num = 100

def create_database(db_name):
    """创建SQLite数据库和表结构"""
    conn = sqlite3.connect(db_name)
    cursor = conn.cursor()

    # 创建主表
    cursor.execute('''
    CREATE TABLE IF NOT EXISTS user_data (
        STATIS_TIME TEXT,
        PROV TEXT,
        PERSON_ID TEXT,
        PHONE_NUM TEXT,
        USER_ID TEXT,
        CUST_ID TEXT,
        ATTR_AGE INTEGER,
        ATTR_GENDER TEXT,
        ATTR_PROVINCE TEXT,
        ATTR_CITY TEXT,
        ATTR_COUNTY TEXT,
        ATTR_GRID_ID TEXT,
        ATTR_GRID_LAT REAL,
        ATTR_GRID_LONG REAL,
        ATTR_DAY_BASE_ID TEXT,
        ATTR_DAY_BASE_LAT REAL,
        ATTR_DAY_BASE_LONG REAL,
        ATTR_NIGHT_BASE_ID TEXT,
        ATTR_NIGHT_BASE_LAT REAL,
        ATTR_NIGHT_BASE_LONG REAL,
        ATTR_FEE_FLUCTUATION TEXT,
        LABEL_IS_GSM INTEGER,
        LABEL_IS_MID INTEGER,
        LABEL_IS_PREM INTEGER,
        LABEL_IS_DIFF INTEGER,
        LABEL_IS_ELDER INTEGER,
        LABEL_IS_INT INTEGER,
        ATTR_FAMILY_CIRCLE_ID TEXT,
        ATTR_GEO_CIRCLE_ID TEXT,
        ATTR_SOCIAL_CIRCLE_ID TEXT,
        ATTR_COMMUNITY_CIRCLE_ID TEXT,
        ATTR_CAMPUS_CIRCLE_ID TEXT,
        ATTR_COMMUTE_CIRCLE_ID TEXT,
        ATTR_BUSINESS_CIRCLE_ID TEXT,
        ATTR_ONLINE_CIRCLE_ID TEXT,
        METRIC_ARPU REAL,
        METRIC_FLUX_USED REAL,
        METRIC_BROADBAND_COUNT INTEGER,
        METRIC_BROADBAND_TRAFFIC REAL,
        METRIC_BROADBAND_ONLINETIME REAL,
        METRIC_MONTHLY_CONSUMPTION REAL,
        METRIC_BASIC_PACKAGE_FEE REAL,
        METRIC_LOCAL_CALL_FEE REAL,
        METRIC_LONG_DISTANCE_CALL_FEE REAL,
        METRIC_DOMESTIC_DATA_FEE REAL,
        METRIC_INTERNATIONAL_DATA_FEE REAL,
        METRIC_ADDITIONAL_SERVICE_FEE REAL,
        METRIC_VALUE_ADDED_SERVICE_FEE REAL,
        METRIC_DATA_USAGE_FEE REAL,
        METRIC_CALL_DURATION_MINUTES_INT INTEGER,
        ATTR_NUMBER_ACTIVATION_DATE TEXT,
        ATTR_NUMBER_PLAN_NAME TEXT,
        METRIC_NUMBER_DATA_ALLOWANCE_GB INTEGER,
        METRIC_NUMBER_FREE_CALL_MINUTES INTEGER,
        ATTR_NUMBER_TERMINATION_DATE TEXT,
        ATTR_NUMBER_REGISTERED_LOCATION TEXT,
        LABEL_NUMBER_PORTABILITY_STATUS TEXT,
        METRIC_LAC_DAY_TOTAL_TIME_MINUTES INTEGER,
        METRIC_LAC_NIGHT_TOTAL_TIME_MINUTES INTEGER,
        METRIC_LAC_DAY_LAC_COUNT INTEGER,
        METRIC_LAC_NIGHT_LAC_COUNT INTEGER,
        ATTR_BRD_ADDR TEXT,
        ATTR_PRODUCT_NAME TEXT,
        ATTR_GROUP_NAME TEXT,
        ATTR_CREDIT_SCORE INTEGER,
        ATTR_ARRIVE_TIME TEXT,
        ATTR_ARRIVE_ADDR TEXT,
        ATTR_ARRIVE_ADD_TYPE TEXT,
        ATTR_ARRIVE_LONGITUDE REAL,
        ATTR_ARRIVE_LATITUDE REAL,
        METRIC_ARRIVE_STAY_TIME INTEGER,
        ATTR_ARRIVE_LAC_CODE TEXT,
        METRIC_CALL_TIMESTAMP TEXT,
        ATTR_CALL_NUMBER TEXT,
        ATTR_CALL_ROAMING_TYPE TEXT,
        METRIC_CALL_DURATION_MINUTES_FLOAT REAL,
        METRIC_CALL_APP_COST_RMB REAL,
        METRIC_TIMESTAMP TEXT,
        METRIC_APP_UPLOAD_TRAFFIC_MB REAL,
        METRIC_APP_DOWNLOAD_TRAFFIC_MB REAL,
        METRIC_APP_ONLINE_DURATION_MINUTES INTEGER,
        ATTR_APP_USED TEXT,
        ATTR_APP_COST_RMB REAL,
        ATTR_GROUP_PRODUCT_NAME TEXT
    )
    ''')

    conn.commit()
    return conn, cursor


def generate_province():
    """生成省份，目前只生成北京用户数据"""
    provinces = ["北京"]
    return random.choice(provinces)


def generate_gender():
    """生成性别"""
    return random.choice(["男", "女"])


def generate_phone_num():
    """生成手机号码"""
    prefixes = ["139", "138", "137", "136", "135", "134", "147", "153", "154", "155", "156", "159", "158", "157", "150", "151", "152", "182", "183", "184", "185", "186", "187", "188", "198"]
    return random.choice(prefixes) + ''.join([str(random.randint(0, 9)) for _ in range(8)])


def generate_id(prefix, count):
    """生成ID"""
    return f"{prefix}{random.randint(1, count):05d}"


def generate_float_range(min_val, max_val, decimal_places=2):
    """生成指定范围内的浮点数"""
    return round(random.uniform(min_val, max_val), decimal_places)


def generate_date(start_year=2010, end_year=2024):
    """生成日期"""
    start_date = datetime(start_year, 1, 1)
    end_date = datetime(end_year, 12, 31)
    return (start_date + timedelta(
        seconds=random.randint(0, int((end_date - start_date).total_seconds()))
    )).strftime("%Y%m%d")


def generate_datetime(start_year=2024, end_year=2024):
    """生成日期时间"""
    start_date = datetime(start_year, 1, 1)
    end_date = datetime(end_year, 12, 31)
    return (start_date + timedelta(
        seconds=random.randint(0, int((end_date - start_date).total_seconds()))
    )).strftime("%Y%m%d %H:%M:%S")


def generate_plan_name():
    """生成套餐名称"""
    mobile_plans = ["移动大王卡", "全球通尊享套餐", "神州行畅聊卡", "5G智享套餐", "和飞享套餐"]
    telecom_plans = ["电信无忧卡", "十全十美套餐", "天翼畅享套餐", "5G融合套餐", "青年一派卡"]
    unicom_plans = ["联通大王卡", "冰淇淋套餐", "沃派套餐", "G畅爽套餐", "校园套餐"]
    all_plans = mobile_plans + telecom_plans + unicom_plans
    return random.choice(all_plans)


def generate_app_name():
    """生成APP名称"""
    apps = ["微信", "抖音", "支付宝", "淘宝", "拼多多", "高德地图", "QQ", "快手", "百度", "京东",
            "小红书", "微博", "美团", "滴滴出行", "哔哩哔哩", "饿了么", "WPS Office", "腾讯视频",
            "爱奇艺", "携程", "夸克", "百度网盘", "Soul", "知乎", "百度地图", "网易新闻", "虎牙直播",
            "番茄小说", "剪映", "懂车帝"]
    return random.choice(apps)


def generate_group_name():
    """生成集团名称"""
    groups = ["阿里巴巴集团", "腾讯控股集团", "中国工商银行集团", "国家电网公司", "华为技术有限公司",
              "中国石油集团", "中国建筑集团", "顺丰控股集团", "新东方教育集团", "华润医药集团"]
    return random.choice(groups)


def generate_product_name():
    """生成产品名称"""
    products = ["移动看家", "移动高清", "移动康养", "移动车家", "移动云盘", "139邮箱", "云手机",
                "云电脑", "行车卫士", "集团语音"]
    return random.choice(products)


def generate_address_type():
    """生成地址类型"""
    types = ["住宅", "公司", "餐厅", "超市", "景点", "影院", "4S店", "小学", "中学", "大学"]
    return random.choice(types)


def generate_roaming_type():
    """生成漫游类型"""
    return random.choice(["国内", "国际"])

def generate_city():
    return random.choice(["东城区", "西城区", "朝阳区", "丰台区", "石景山区", "海淀区", "顺义区", "通州区", "大兴区", "房山区", "门头沟区", "昌平区", "平谷区", "密云区", "怀柔区", "延庆区"])

def generate_county(city):
    beijing_districts_streets = {
        "东城区": [
            "东华门街道", "景山街道", "交道口街道", "安定门街道", "北新桥街道",
            "东四街道", "朝阳门街道", "建国门街道", "东直门街道", "和平里街道",
            "前门街道", "崇文门外街道", "东花市街道", "龙潭街道", "体育馆路街道",
            "天坛街道", "永定门外街道"
        ],
        "西城区": [
            "西长安街街道", "新街口街道", "月坛街道", "展览路街道", "德胜街道",
            "金融街街道", "什刹海街道", "大栅栏街道", "天桥街道", "椿树街道",
            "陶然亭街道", "广安门内街道", "牛街街道", "白纸坊街道", "广安门外街道"
        ],
        "朝阳区": [
            "建外街道", "朝外街道", "呼家楼街道", "三里屯街道", "左家庄街道",
            "香河园街道", "和平街街道", "安贞街道", "亚运村街道", "小关街道",
            "酒仙桥街道", "麦子店街道", "团结湖街道", "六里屯街道", "八里庄街道",
            "双井街道", "劲松街道", "潘家园街道", "垡头街道", "南磨房地区",
            "高碑店地区", "将台地区", "太阳宫地区", "大屯街道", "望京街道",
            "小红门地区", "十八里店地区", "平房地区", "东风地区", "奥运村街道",
            "来广营地区", "常营地区", "三间房地区", "管庄地区", "金盏地区",
            "孙河地区", "崔各庄地区", "东坝地区", "黑庄户地区", "王四营地区"
        ],
        "丰台区": [
            "右安门街道", "太平桥街道", "西罗园街道", "大红门街道", "南苑街道",
            "东高地街道", "东铁匠营街道", "卢沟桥街道", "丰台街道", "新村街道",
            "长辛店街道", "云岗街道", "方庄地区", "宛平地区", "马家堡街道",
            "和义街道", "卢沟桥乡", "花乡", "南苑乡", "长辛店镇", "王佐镇"
        ],
        "石景山区": [
            "八宝山街道", "老山街道", "八角街道", "古城街道", "苹果园街道",
            "金顶街街道", "广宁街道", "五里坨街道", "鲁谷街道"
        ],
        "海淀区": [
            "万寿路街道", "永定路街道", "羊坊店街道", "甘家口街道", "八里庄街道",
            "紫竹院街道", "北下关街道", "北太平庄街道", "学院路街道", "中关村街道",
            "海淀街道", "青龙桥街道", "清华园街道", "燕园街道", "香山街道",
            "清河街道", "花园路街道", "西三旗街道", "马连洼街道", "田村路街道",
            "上地街道", "万柳地区", "东升地区", "曙光街道", "温泉镇",
            "四季青镇", "西北旺镇", "上庄镇", "苏家坨镇"
        ],
        "门头沟区": [
            "大峪街道", "城子街道", "东辛房街道", "大台街道", "王平镇",
            "永定镇", "龙泉镇", "潭柘寺镇", "军庄镇", "妙峰山镇",
            "雁翅镇", "斋堂镇", "清水镇"
        ],
        "房山区": [
            "城关街道", "新镇街道", "向阳街道", "东风街道", "迎风街道",
            "星城街道", "良乡地区", "周口店地区", "琉璃河地区", "拱辰街道",
            "西潞街道", "阎村镇", "窦店镇", "石楼镇", "长阳镇",
            "河北镇", "长沟镇", "大石窝镇", "张坊镇", "十渡镇",
            "青龙湖镇", "韩村河镇", "霞云岭乡", "南窖乡", "佛子庄乡",
            "大安山乡", "史家营乡", "蒲洼乡"
        ],
        "通州区": [
            "中仓街道", "新华街道", "北苑街道", "玉桥街道", "永顺镇",
            "梨园镇", "宋庄镇", "张家湾镇", "漷县镇", "马驹桥镇",
            "西集镇", "台湖镇", "永乐店镇", "潞城镇", "于家务回族乡",
            "文景街道", "九棵树街道", "临河里街道", "杨庄街道", "潞邑街道"
        ],
        "顺义区": [
            "胜利街道", "光明街道", "仁和地区", "后沙峪地区", "天竺地区",
            "杨镇地区", "牛栏山地区", "南法信地区", "马坡地区", "石园街道",
            "空港街道", "双丰街道", "旺泉街道", "高丽营镇", "李桥镇",
            "李遂镇", "南彩镇", "北务镇", "大孙各庄镇", "张镇",
            "龙湾屯镇", "木林镇", "北小营镇", "北石槽镇", "赵全营镇"
        ],
        "昌平区": [
            "城北街道", "城南街道", "天通苑北街道", "天通苑南街道", "霍营街道",
            "回龙观街道", "龙泽园街道", "史各庄街道", "阳坊镇", "小汤山镇",
            "南口镇", "崔村镇", "百善镇", "东小口镇", "北七家镇",
            "兴寿镇", "流村镇", "十三陵镇", "延寿镇", "沙河地区",
            "马池口地区"
        ],
        "大兴区": [
            "兴丰街道", "林校路街道", "清源街道", "亦庄地区", "黄村地区",
            "旧宫地区", "西红门地区", "瀛海地区", "观音寺街道", "天宫院街道",
            "高米店街道", "荣华街道", "博兴街道", "青云店镇", "采育镇",
            "安定镇", "礼贤镇", "榆垡镇", "庞各庄镇", "北臧村镇",
            "魏善庄镇", "长子营镇"
        ],
        "怀柔区": [
            "泉河街道", "龙山街道", "怀柔地区", "雁栖地区", "庙城地区",
            "北房镇", "杨宋镇", "桥梓镇", "怀北镇", "汤河口镇",
            "渤海镇", "九渡河镇", "琉璃庙镇", "宝山镇", "长哨营满族乡",
            "喇叭沟门满族乡"
        ],
        "平谷区": [
            "滨河街道", "兴谷街道", "渔阳地区", "峪口地区", "马坊地区",
            "金海湖地区", "东高村镇", "山东庄镇", "南独乐河镇", "大华山镇",
            "夏各庄镇", "马昌营镇", "王辛庄镇", "大兴庄镇", "刘家店镇",
            "镇罗营镇", "黄松峪乡", "熊儿寨乡"
        ],
        "密云区": [
            "鼓楼街道", "果园街道", "檀营地区", "密云镇", "溪翁庄镇",
            "西田各庄镇", "十里堡镇", "河南寨镇", "巨各庄镇", "穆家峪镇",
            "太师屯镇", "高岭镇", "不老屯镇", "冯家峪镇", "古北口镇",
            "大城子镇", "东邵渠镇", "北庄镇", "新城子镇", "石城镇"
        ],
        "延庆区": [
            "百泉街道", "儒林街道", "延庆镇", "康庄镇", "八达岭镇",
            "永宁镇", "旧县镇", "张山营镇", "四海镇", "千家店镇",
            "沈家营镇", "大榆树镇", "井庄镇", "刘斌堡乡", "香营乡",
            "珍珠泉乡", "大庄科乡"
        ]
    }
    return random.choice(beijing_districts_streets[city])

def generate_user_data(date, num):
    """生成用户数据"""
    data = []
    for user_count in range(num):

        prov = generate_province()
        gender = generate_gender()
        phone_num = generate_phone_num()
        person_id = generate_id("P", 99999)
        user_id = generate_id("U", 99999)
        cust_id = generate_id("C", 99999)
        age = random.randint(18, 80)

        # 生成常驻基站和网格坐标
        day_base_id = generate_id("B", 9999)
        night_base_id = generate_id("B", 9999)
        grid_id = generate_id("G", 999)

        # 生成圈ID
        family_circle = generate_id("FC", 999)
        geo_circle = generate_id("GEO", 999)
        social_circle = generate_id("SC", 999)
        community_circle = generate_id("CYC", 999)
        campus_circle = generate_id("CPC", 999)
        commute_circle = generate_id("CTC", 999)
        business_circle = generate_id("BC", 999)
        online_circle = generate_id("OC", 999)

        # 生成消费相关指标
        arpu = generate_float_range(15, 300)
        flux_used = generate_float_range(100, 2097152, 2)
        monthly_consumption = generate_float_range(50, 300)

        # 生成通话相关指标
        call_duration_int = random.randint(2, 300)
        call_duration_float = generate_float_range(0.1, 60.0, 1)

        # 生成时间相关数据
        statis_time = date  # 固定统计时间
        activation_date = generate_date(2010, 2023)
        termination_date = generate_date(2023, 2024) if random.random() < 0.1 else ""  # 10%用户有离网日期

        # 生成位置数据
        arrive_time = generate_datetime()
        stay_time = random.randint(5, 600)

        # 生成信用分
        credit_score = random.randint(420, 696)

        # 生成APP使用数据
        app_used = generate_app_name()
        app_upload = generate_float_range(0.1, 10.0, 2)
        app_download = generate_float_range(0.1, 50.0, 2)
        app_online_duration = random.randint(1, 120)

        city = fake.city() if prov != "北京" else generate_city()
        county = fake.district() if prov != "北京" else generate_county(city)
        record = (
            statis_time,  # STATIS_TIME
            prov,  # PROV
            person_id,  # PERSON_ID
            phone_num,  # PHONE_NUM
            user_id,  # USER_ID
            cust_id,  # CUST_ID
            age,  # ATTR_AGE
            gender,  # ATTR_GENDER
            f"{prov}市",  # ATTR_PROVINCE
            city,  # ATTR_CITY
            county,  # ATTR_COUNTY
            grid_id,  # ATTR_GRID_ID
            generate_float_range(39.43, 41.05, 2),  # ATTR_GRID_LAT
            generate_float_range(115.25, 117.30, 2),  # ATTR_GRID_LONG
            day_base_id,  # ATTR_DAY_BASE_ID
            generate_float_range(39.43, 41.05, 2),  # ATTR_DAY_BASE_LAT
            generate_float_range(115.25, 117.30, 2),  # ATTR_DAY_BASE_LONG
            night_base_id,  # ATTR_NIGHT_BASE_ID
            generate_float_range(39.43, 41.05, 2),  # ATTR_NIGHT_BASE_LAT
            generate_float_range(115.25, 117.30, 2),  # ATTR_NIGHT_BASE_LONG
            random.choice(["稳定型", "波动型"]),  # ATTR_FEE_FLUCTUATION
            random.randint(0, 1),  # LABEL_IS_GSM
            random.randint(0, 1),  # LABEL_IS_MID
            random.randint(0, 1),  # LABEL_IS_PREM
            random.randint(0, 1),  # LABEL_IS_DIFF
            random.randint(0, 1),  # LABEL_IS_ELDER
            random.randint(0, 1),  # LABEL_IS_INT
            family_circle,  # ATTR_FAMILY_CIRCLE_ID
            geo_circle,  # ATTR_GEO_CIRCLE_ID
            social_circle,  # ATTR_SOCIAL_CIRCLE_ID
            community_circle,  # ATTR_COMMUNITY_CIRCLE_ID
            campus_circle,  # ATTR_CAMPUS_CIRCLE_ID
            commute_circle,  # ATTR_COMMUTE_CIRCLE_ID
            business_circle,  # ATTR_BUSINESS_CIRCLE_ID
            online_circle,  # ATTR_ONLINE_CIRCLE_ID
            arpu,  # METRIC_ARPU
            flux_used,  # METRIC_FLUX_USED
            random.randint(0, 3),  # METRIC_BROADBAND_COUNT
            generate_float_range(1000, 500000, 0),  # METRIC_BROADBAND_TRAFFIC
            generate_float_range(1000, 100000, 0),  # METRIC_BROADBAND_ONLINETIME
            monthly_consumption,  # METRIC_MONTHLY_CONSUMPTION
            generate_float_range(30, 100, 2),  # METRIC_BASIC_PACKAGE_FEE
            generate_float_range(0, 50, 2),  # METRIC_LOCAL_CALL_FEE
            generate_float_range(0, 30, 2),  # METRIC_LONG_DISTANCE_CALL_FEE
            generate_float_range(0, 100, 2),  # METRIC_DOMESTIC_DATA_FEE
            generate_float_range(0, 50, 2),  # METRIC_INTERNATIONAL_DATA_FEE
            generate_float_range(0, 30, 2),  # METRIC_ADDITIONAL_SERVICE_FEE
            generate_float_range(0, 50, 2),  # METRIC_VALUE_ADDED_SERVICE_FEE
            generate_float_range(0, 20, 2),  # METRIC_DATA_USAGE_FEE
            call_duration_int,  # METRIC_CALL_DURATION_MINUTES_INT
            activation_date,  # ATTR_NUMBER_ACTIVATION_DATE
            generate_plan_name(),  # ATTR_NUMBER_PLAN_NAME
            random.randint(5, 100),  # METRIC_NUMBER_DATA_ALLOWANCE_GB
            random.randint(100, 1000),  # METRIC_NUMBER_FREE_CALL_MINUTES
            termination_date,  # ATTR_NUMBER_TERMINATION_DATE
            fake.address(),  # ATTR_NUMBER_REGISTERED_LOCATION
            random.choice(["是", "否"]),  # LABEL_NUMBER_PORTABILITY_STATUS
            random.randint(500, 1000),  # METRIC_LAC_DAY_TOTAL_TIME_MINUTES
            random.randint(300, 800),  # METRIC_LAC_NIGHT_TOTAL_TIME_MINUTES
            random.randint(5, 20),  # METRIC_LAC_DAY_LAC_COUNT
            random.randint(2, 10),  # METRIC_LAC_NIGHT_LAC_COUNT
            fake.address(),  # ATTR_BRD_ADDR
            generate_product_name(),  # ATTR_PRODUCT_NAME
            generate_group_name(),  # ATTR_GROUP_NAME
            credit_score, # ATTR_CREDIT_SCORE
            arrive_time,  # ATTR_ARRIVE_TIME
            fake.address(),  # ATTR_ARRIVE_ADDR
            generate_address_type(),  # ATTR_ARRIVE_ADD_TYPE
            generate_float_range(115.25, 117.30, 4),  # ATTR_ARRIVE_LONGITUDE
            generate_float_range(39.43, 41.05, 4),  # ATTR_ARRIVE_LATITUDE
            stay_time,  # METRIC_ARRIVE_STAY_TIME
            generate_id("L", 9999),  # ATTR_ARRIVE_LAC_CODE
            generate_datetime(),  # METRIC_CALL_TIMESTAMP
            generate_phone_num(),  # ATTR_CALL_NUMBER
            generate_roaming_type(),  # ATTR_CALL_ROAMING_TYPE
            call_duration_float,  # METRIC_CALL_DURATION_MINUTES_FLOAT
            generate_float_range(0, 10, 2),  # METRIC_CALL_APP_COST_RMB
            generate_datetime(),  # METRIC_TIMESTAMP
            app_upload,  # METRIC_APP_UPLOAD_TRAFFIC_MB
            app_download,  # METRIC_APP_DOWNLOAD_TRAFFIC_MB
            app_online_duration,  # METRIC_APP_ONLINE_DURATION_MINUTES
            app_used,  # ATTR_APP_USED
            generate_float_range(0, 50, 2),  # ATTR_APP_COST_RMB
            generate_product_name()  # ATTR_GROUP_PRODUCT_NAME
        )
        data.append(record)

    return data

def iterate_daily(start_date: str, end_date: str, date_format: str = "%Y-%m-%d") -> Generator[datetime, None, None]:
    """
    遍历指定时间段内的每一天

    Args:
        start_date: 开始日期字符串，格式由date_format指定
        end_date: 结束日期字符串，格式由date_format指定
        date_format: 日期格式，默认为"%Y-%m-%d"

    Yields:
        datetime: 每天的日期对象

    Example:
        # >>> for day in iterate_daily("2024-01-01", "2024-01-05"):
        # ...     print(day.strftime("%Y-%m-%d"))
        2024-01-01
        2024-01-02
        2024-01-03
        2024-01-04
        2024-01-05
    """
    start_dt = datetime.strptime(start_date, date_format)
    end_dt = datetime.strptime(end_date, date_format)

    current_dt = start_dt
    while current_dt <= end_dt:
        yield current_dt
        current_dt += timedelta(days=1)


def main():
    """主函数"""
    db_name = "sqlite_data.db"

    print("正在创建数据库和表结构...")
    conn, cursor = create_database(db_name)

    date_diff = datetime.strptime(end_date, "%Y-%m-%d") - datetime.strptime(start_date, "%Y-%m-%d")
    print(f"正在生成 {daily_gene_num * (date_diff.days + 1)} 条数据...")
    start_time = time.time()

    for day in iterate_daily(start_date, end_date):
        data = generate_user_data(day.strftime("%Y%m%d"), daily_gene_num)
        # 批量插入数据 84个字段
        cursor.executemany('''
            INSERT INTO user_data VALUES (
                ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 
                ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 
                ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 
                ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 
                ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 
                ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 
                ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 
                ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 
                ?, ?, ?, ?
            )
            ''', data)
        conn.commit()


    end_time = time.time()
    print(f"数据生成完成，耗时: {end_time - start_time:.2f} 秒")

    # 显示统计信息
    cursor.execute("SELECT COUNT(*) FROM user_data")
    count = cursor.fetchone()[0]
    print(f"数据库中的总记录数: {count}")

    conn.close()
    print("程序执行完成!")


if __name__ == "__main__":
    main()